<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require dirname(__FILE__).'/pc_controller.php';

require_once dirname(__FILE__).'/menu.php';

class All_customer extends PC_controller {

    public function __construct(){
        parent::__construct();
        $this->load->model('Allcustomermodel','m_customer');
    }

    public function index(){
        $data = parent::index();

        $this->load->view('admin/all_customer',$data);
    }

    public function getCustomerList(){
        $assist['where'] = getFilter($this->input->post(),Allcustomermodel::$searchField);
        $assist['like'] = getFilter($this->input->post(),Allcustomermodel::$likeField);
        $assist['sort'] = getSort($this->input->post(),Allcustomermodel::$sortField);
        $assist['pagination'] = getPagination($this->input->post());

        list($list,$count) = $this->m_customer->getCustomerListSection($assist);

        foreach ($list as $key => $value) {
            $list[$key]['nickname'] = urldecode($value['nickname']);
        }

        $this->response->setSuccess();
        $this->response->setItems($list);
        $this->response->setTotalCount($count);
        $this->response->responseExit();
    }

    public function makeAccess() {
        $this->validate->setRule('start','integer');
        $this->validate->setRule('limit','integer');
        if(!$this->validate->run($this->input->post())){
            $this->response->setDetail($this->validate->getMessage());
            $this->response->responseExit();
        }
        $info = $this->validate->getResult();
        $assist['pagination'] = getPagination($this->input->post());

        list($list,$count) = $this->m_customer->getCustomerListSection($assist);

        $url_list = array();
        foreach ($list as $key => $customer) {
        	unset($customer['customer_id']);
        	$customer['nickname'] = urlencode($customer['nickname']);
        	$customer['province'] = urlencode($customer['province']);
        	$customer['city'] = urlencode($customer['city']);
        	$customer['country'] = urlencode($customer['country']);
        	$customer['state'] = 'makePhoto';
        	$customer['openid_md5'] = md5($customer['openid'].FREEDOM_WAR_SALT);
        	$param = http_build_query($customer);
        	$url_list[] = 'http://weixin.chenyang.com/weixin/2016_makePhoto/h5/index.html#'.$param;
        }

        $this->response->setSuccess();
        $this->response->setItems($url_list);
        $this->response->responseExit();
    }

    public function enableCustomer() {
        $this->validate->setRule('customer_id','integer');
        $this->validate->setRule('customer_id','message',$this->lang->line('error_parameter'));
        if(!$this->validate->run($this->input->post())){
            $this->response->setDetail($this->validate->getMessage());
            $this->response->responseExit();
        }
        $info = $this->validate->getResult();

        $info['customer_status'] = STATUS_DISABLE;
        $this->m_customer->editCustomer($info);

        $this->response->setSuccess();
        $this->response->setDetail('更新成功!');
        $this->response->responseExit();
    }
}
/* End of file customer.php */
/* Location: ./application/controllers/customer.php */